import time
import requests

def download_video(url: str, out_path: str, referer: str = "https://www.douyin.com/"):
    print("download")
    headers = {
        "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
                       "AppleWebKit/537.36 (KHTML, like Gecko) "
                       "Chrome/120.0 Safari/537.36"),
        "Referer": referer,
        "Accept": "*/*",
        "Accept-Language": "zh-CN,zh;q=0.9",
    }
    with requests.get(url, headers=headers, stream=True, timeout=20) as r:
        r.raise_for_status()
        with open(out_path, "wb") as f:
            for chunk in r.iter_content(chunk_size=8192):
                if chunk:
                    f.write(chunk)

if __name__ == "__main__":
    URL = "https://v3-web.douyinvod.com/0babddd8c28e46772edcfbb8b6c94066/68c40852/video/tos/cn/tos-cn-ve-15/oQlB1mLg5QGelvgAWyaAeFIRRDIV7gfBaLwsEC/?a=6383&ch=26&cr=3&dr=0&lr=all&cd=0%7C0%7C0%7C3&cv=1&br=3268&bt=3268&cs=2&ds=10&ft=4TMWc6DhppftrdLv.sQ.C_fauVq0In_V_kGc6BI7ZsVLYGdHDDB9obhiZMPsuusZ.&mime_type=video_mp4&qs=15&rc=PDM4OTNoaWczNjk1OzVnZUBpanZ5N3U5cm5wNjMzNGkzM0AvMGFjYTNjNmExYjM1YDEvYSNwaV9uMmRrMi1hLS1kLWFzcw%3D%3D&btag=c0000e00008000&cquery=100w_100B_100x_100z_100o&dy_q=1757666836&feature_id=93a58339ca02382e145ecd93f89a5899&l=202509121647164AE449AD3D6401778F9E"
    download_video(URL, f"../temp/video_temp/video{time.time()}.mp4")
    print("done")